package com.itheima.chapter08.collection;

import java.util.ArrayList;
import java.util.Collection;
//常用方法
public class demo1 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        method01(collection);//添加元素
        System.out.println(collection);
        method02(collection);//从集合中移除指定元素
        System.out.println(collection);
        method03(collection);//根据条件进行删除
        System.out.println(collection);
        collection.clear();//清空集合
        System.out.println(collection);
        boolean r3 = collection.contains("aaa");
        System.out.println(r3);
        boolean empty = collection.isEmpty();
        System.out.println(empty);
        int size = collection.size();
        System.out.println(size);
        //System.out.println(collection);


    }

    private static void method03(Collection<String> collection) {
        collection.removeIf(
                (String s) -> {
                    return s.length() ==3 ;
                    //底层逻辑遍历集合中元素，s依次表示集合中元素
                });
    }

    private static void method02(Collection<String> collection) {
        boolean r1 = collection.remove("aaa");
        boolean r2 = collection.remove("ddd");
    }

    private static void method01(Collection<String> collection) {
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("ddd");
        collection.add("abcde");
        collection.add("abcd");


    }
}
